//
//  RegisterViewController.m
//  PerfectWorld
//
//  Created by dllo on 16/9/22.
//  Copyright © 2016年 LST. All rights reserved.
//  注册界面

#import "RegisterViewController.h"
#import "AFNetworking.h"
#import "NetworkHandler.h"
#import "TextNameViewController.h"
#import "Masonry.h"
@interface RegisterViewController ()
@property (nonatomic, strong)UITextField *textFieldPhone;
@property (nonatomic, strong)UITextField *textFieldPassWord;
@property (nonatomic, strong)UITextField *downTextField;
@property (nonatomic, copy)NSString *strCode;
@property (nonatomic, strong)UIButton *btn;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"注册新账号";
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBtn:)];
    [self creatSubView];
    
}
- (void)creatSubView {
    _textFieldPhone = [[UITextField alloc] init];
    _textFieldPhone.placeholder = @"请输入手机号";
    [self.view addSubview:_textFieldPhone];
    [_textFieldPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.width.mas_equalTo (self.view.frame.size.width - 30);
        make.height.mas_equalTo (50);
        make.left.mas_equalTo (15);
    }];
    _textFieldPassWord = [[UITextField alloc] init];
    _textFieldPassWord.placeholder = @"请输入验证码";
    [self.view addSubview:_textFieldPassWord];
    [_textFieldPassWord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo (_textFieldPhone.mas_bottom).offset(20);
        make.left.height.mas_equalTo (_textFieldPhone);
        make.width.mas_equalTo (self.view.frame.size.width / 2);
    }];
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btn setTitle:@"点击获取验证码" forState:UIControlStateNormal];
    _btn.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:_btn];
    [_btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_textFieldPassWord.mas_right).offset(10);
        make.height.mas_equalTo (_textFieldPassWord);
        make.centerY.mas_equalTo (_textFieldPassWord.mas_centerY);
        make.width.mas_equalTo (_textFieldPassWord.mas_width);
    }];
    self.downTextField = [[UITextField alloc] init];
    _downTextField.placeholder = @"请输入登录密码";
    [self.view addSubview:_downTextField];
    [_downTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.width.mas_equalTo (_textFieldPhone);
        make.top.mas_equalTo(_textFieldPassWord.mas_bottom).offset(10);
    }];
}
// 15842665915
- (void)handYZData {
    NSString *strUrl = @"http://api.guju.com.cn/v2/personal/mobile/code2";
    NSString *strBody = [NSString stringWithFormat:@"phone=%@", _textFieldPhone.text];
   [NetworkHandler getDataByUrlString:strUrl BodyString:strBody WithDataBlock:^(id result) {
       NSDictionary *dic = result;
       _strCode = dic[@"code"];
   }];
}
- (void)clickBtn:(UIButton *)sender {
    [self handYZData];
}
- (void)clickRightBtn:(UIBarButtonItem *)sender {
    if ([_textFieldPassWord.text isEqualToString:_strCode]&&_downTextField.text != nil) {
        TextNameViewController *textNameVC = [[TextNameViewController alloc] init];
        textNameVC.passWorld = _downTextField.text;
        textNameVC.login = _textFieldPhone.text;
        [self.navigationController pushViewController:textNameVC animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
